﻿using Furion.DependencyInjection;
using Microsoft.Extensions.Caching.Distributed;
using System.Windows;
using System.Windows.Controls;
using UpperComputer.WPF.Entry.Common;
using UpperComputer.WPF.Entry.Common.Extensions;
using UpperComputer.WPF.Entry.ViewModels;

namespace UpperComputer.WPF.Entry.Views;

/// <summary>
/// UserRoleSelectControl.xaml 的交互逻辑
/// </summary>
public partial class UserRoleSelectControl : UserControl, ITransient
{
    private readonly IDistributedCache _distributedCache;

    public UserRoleSelectControl(
        UserRoleSelectViewModel userRoleSelectViewModel,
        IDistributedCache distributedCache)
    {
        InitializeComponent();
        DataContext = userRoleSelectViewModel;
        _distributedCache = distributedCache;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (RoleTree.SelectedItem == null)
        {
            Snackbar.ShowWarningMessage("请选择菜单");
            return;
        }
        DialogTop.CloseDialog(RoleTree.SelectedItem);
    }

    private async void DialogTop_OnDialogClosing(object sender, RoutedEventArgs e)
    {
        await _distributedCache.RemoveAsync(Constant.CACHE_KEY_Role_CODE);
    }
}
